/*
* EP-Tracing System : a tool to trace mountain hike.           .kNNx
* Copyright (C) 2009  Raffaello Brondi                         'KNNNk
*                                                             ,XNNNl
* This program is free software:                             ,XNN0'
* you can redistribute it and/or modify                     ,XNNx.
* it under the terms of the                                'XNNl
* GNU General Public License                              .KNN:                     ..
* as published by                                        .0NNo                    .ONNO.
* the Free Software Foundation,                          xNNN.  :dkd,            .KNNNN;
* either version 3 of the License, or                   :NNNK ;XNNNNNo          ,KNNNX:
* (at your option) any later version.                   xNNNNcXNNNNNNk         cNNNNx.
*                                                       ,XNNNNNNNNNNX'       .xNNNK;
*                                                        .lKNNNNNNNK'       :KNNNo
*                                                          ;kNNNNNKxl;'.'l0NNNk.
* This program is distributed in                          .'  .:xXNNNNNNNNNNNO,
* the hope that it will be useful,                       :NNXd'   ,oONNNNNNk,
* but WITHOUT ANY WARRANTY;                              xNNNNN0c.    .;;,.
* without even the implied warranty of                   kNNNNNNNXd'
* MERCHANTABILITY or                                     xNNNNNNNNNNOc.
* FITNESS FOR A PARTICULAR PURPOSE.                      xNNNNNNNNNNNNXd.
* See the GNU General Public License                     ONNNN0.,o0NNNNNNl
* for more details.                                      0NNNNd    kNNNNNX.
*                                                        KNNNNl   oNNNNNXc
*                                                       .XNNNN:  dNNNNNx.
* You should have received a copy                       .XNNNN; lNNNNO'
* of the GNU General Public License                     .XNNNN; 'dxo'
* along with this program.                              .XNNNN;
* If not, see <http://www.gnu.org/licenses/>.            0NNNN:
*                                                        kNNNNc
*                                                        oNNNNd
*                                                        ;NNNN0
* Contact: rbrondi@gmail.com                             .XNNNN;
*                                                         kNNNNd
*                                                         .coo:.
*/

package EP.GPS;


import java.util.Vector;
import javax.microedition.location.Criteria;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Raffaello Brondi
 */
public class Trip {
    /**  Low precision --> 100 meters   */
    private final int PRECISION_LOW = 100;
    /**  Low-medium precision --> 75 meters   */
    private final int PRECISION_LOW_MEDIUM = 75;
    /**  Medium precision --> 50 meters   */
    private final int PRECISION_MEDIUM = 50;
    /**  Medium-high precision --> 25 meters   */
    private final int PRECISION_MEDIUM_HIGH = 25;
    /**
     * High precision --> 5 meters
     */
    private final int PRECISION_HIGH = 5;

    /*private final int POWER_LOW = Criteria.POWER_USAGE_LOW;
    private final int POWER_MEDIUM = Criteria.POWER_USAGE_MEDIUM;
    private final int POWER_HIGH = Criteria.POWER_USAGE_HIGH;

    private final int NO_REQUIREMENTS = 0;*/

    private byte precision;
    private byte powerConsumption;

    private String tripName;
    private byte storage;
    private Vector roots;

    private boolean altitude;
    private boolean costProviderAllowed;

    public Trip(Vector roots){
        this.roots = roots;
        this.storage = -1;
        this.precision = 0;
        this.tripName = "default";
        this.altitude = false;
        this.costProviderAllowed = false;
        this.powerConsumption = 0;
    }

    public void setPrecision(byte p){
       this.precision = p;
    }

    public void setTripName(String name){
       this.tripName = name;
    }

    public void setAltitude(boolean b){
       this.altitude = b;
    }

    public void setCostProviderAllowed(boolean b){
       this.costProviderAllowed = b;
    }

    public void setStorage(byte s){
       this.storage = s;
    }

    public void setPowerConsumption(byte c){
        this.powerConsumption = c;
    }

    /**
     * Returns an int representing the survey precision requested by the user.
     * It uses PRECISION_* predefined values.
     * @return The value of the precision requested by the user.
     */
    public int getPrecision(){
        switch(this.precision){
            case 1:
                return this.PRECISION_LOW;

            case 2:
                return this.PRECISION_LOW_MEDIUM;

            case 3:
                return this.PRECISION_MEDIUM;

            case 4:
                return this.PRECISION_MEDIUM_HIGH;

            case 5:
                return this.PRECISION_HIGH;

            default:
                return this.PRECISION_LOW;
        }
    }

    /**
     * Creates a new Criteria instance tuned with the user trip parameter.
     * @return A new Criteria
     */
    public Criteria getTripCriteria(){
        Criteria c = new Criteria();
        c.setHorizontalAccuracy(this.getPrecision());
        c.setVerticalAccuracy(this.getPrecision());
        c.setPreferredResponseTime(Criteria.NO_REQUIREMENT);
        c.setPreferredPowerConsumption(this.powerConsumption);
        c.setCostAllowed(this.costProviderAllowed);
        c.setSpeedAndCourseRequired(false);
        c.setAltitudeRequired(this.altitude);
        c.setAddressInfoRequired(false);

        return c;
    }

    public boolean isAltitudeNeeded(){
        return this.altitude;
    }
}
